package com.shxy.common.utils;

import com.shxy.common.enums.RoleCode;

import javax.persistence.AttributeConverter;

/**
 * 角色个数转换器
 */
public class RoleConverter implements AttributeConverter<RoleCode, Integer> {
    @Override
    public Integer convertToDatabaseColumn(RoleCode roleCode) {
        if(roleCode == null){
            throw new RuntimeException("Unknown Role text : " + roleCode);
        }
        return roleCode.getCode();
    }

    @Override
    public RoleCode convertToEntityAttribute(Integer code) {
        return RoleCode.getByCode(code);
    }
}
